﻿using Super.Collection.Core;
using Super.Collection.Core.Providers.Welfare;
using Super.Collection.Visual.Datas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Super.Collection.Visual.Workers
{
	class ShuangSeQiuWorker : IWorker
	{
		public void Run()
		{
			// 双色球开奖时间（每周二、四、日开奖，21：30）

			DayOfWeek dayOfWeek = DateTime.Today.DayOfWeek;
			TimeSpan timeOfDay = DateTime.Now.TimeOfDay;

			bool dateCondition = true;//dayOfWeek == DayOfWeek.Tuesday || dayOfWeek == DayOfWeek.Thursday || dayOfWeek == DayOfWeek.Sunday;
			bool timeCondition = true;// timeOfDay >= TimeSpan.Parse("21:30");
			
			if (dateCondition)
			{
				if (timeCondition)
				{
					ChinaWelfareLotteryNet net = new ChinaWelfareLotteryNet();
					try
					{
						NLotteryDraw nLotteryDraw = net.GetLatestLotteryDraw();
						//if (nLotteryDraw.DrawDate == DateTime.Today)
						{
							// 入库
							LotteryDraw lotteryDraw = new LotteryDraw();
							lotteryDraw.Issuer = nLotteryDraw.Issuer;
							lotteryDraw.Game = nLotteryDraw.Game;
							lotteryDraw.IssueNumber = nLotteryDraw.IssueNumber;
							lotteryDraw.DrawDate = nLotteryDraw.DrawDate;
							lotteryDraw.Numbers = nLotteryDraw.Numbers;
							lotteryDraw.BonusNumbers = nLotteryDraw.BonusNumbers;
							lotteryDraw.Bets = nLotteryDraw.Bets;
							lotteryDraw.CumulativeAmount = nLotteryDraw.CumulativeAmount;
							lotteryDraw.CollectionSource = "www.chinafcw.com.cn";

							List<WinningDetail> winningDetails = new List<WinningDetail>();
							foreach (var nWinningDetail in nLotteryDraw.WinningDetails)
							{
								WinningDetail winningDetail = new WinningDetail();
								winningDetail.Serial = nWinningDetail.Serial;
								winningDetail.Award = nWinningDetail.Award;
								winningDetail.NumberOfWinners = nWinningDetail.NumberOfWinners;
								winningDetail.MoneyPerWinner = nWinningDetail.MoneyPerWinner;
								winningDetails.Add(winningDetail);
							}

							DataOperaion.Save(lotteryDraw, winningDetails);
						}
					}
					catch
					{

					}
				}
			}
		}
	}
}
